/**
 * XML Functional Dependence
 * ---------------------------
 * 
 * This class represents a functional dependence
 * XML with the transformation of path expressions in
 * Finite automata.
 * Thus we have:
 *
 * xdf = (M, (T'-> T"))
 *
 * where:
 * M and the context path;
 * T'and the source path or left side;
 * T"and the destination path or right side;
 * 
 * @author Eder P. C. Flor
 */
package model.constraints;

import automata.Fsa;

public class XDF extends AbstractConstraint {
	
	private static final long serialVersionUID = 1L;

	public XDF(String name, Fsa f1, Fsa f2, Fsa f3){
		nameConstraint = name;
		contextFsa = f1;
		sourceFsa = f2;
		targetFsa = f3;
	}

	public XDF() {}
		
	/**
	 * From fsa we know which type of contextFsa, sourceFsa, targetFsa or conditional
	 * @param Object FSA
	 * @return integer 1 is contextFSA, 2 source FSA or 3 targetFSA
	 */
	public int getFsaPosition(Fsa f){
		if (f == contextFsa)
			return 1;
		if (f == sourceFsa)
			return 2;
		if (f == targetFsa)
			return 3;	
		else
			return 0;
	}	

	public String toStringPath() {
		String str = new String();
		str += "<b>XDF Name:</b> " + nameConstraint + "<br><br>";
		str += "<b>Constraint name:</b> " + context + "<br><br>";
		str += "<b>Left Path:</b> " + leftPath +  "<br><br>";
		str += "<b>Type of equality Left:</b> " + leftValue + "<br><br>";
		str += "<b>Right Path:</b> " + rightPath +  "<br><br>";
				
		if(rightValue == 0)
			str += "<b>Type of equality Right:</b> Value<br>";
		else
			str += "<b>Type of equality Right:</b> Node<br>";
		
		return str;
	}
	   
	public String toString() {
		String str = new String();
		str += "<b>XDF Name:</b> " + nameConstraint +  "<br><br>";
		str += "<b>Fsa Context:</b> " + contextFsa.toStringWeb() + "<br>";
		str += "<b>Fsa Source:</b> " + sourceFsa.toStringWeb() + "<br>";
		str += "<b>Fsa Target:</b> " + targetFsa.toStringWeb() + "<br>";
		str += "<b>Paths:</b> " + npaths + "<br>";
		return str;
	}
}
